package org.happen.android.core.data.image;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;

import android.graphics.Bitmap;

public class CacheInfo implements Serializable
{
	static final long serialVersionUID = -9063235922001045101L;
	long creatAt = 0L;
	URL url = null;
	String fileName = null;
	long fileSize = 0L;
	Bitmap value;
	int usetimes;
	int quality = 100;

	CacheInfo()
	{
		this(null);
	}

	CacheInfo(URL url)
	{
		this(url, 0, null);
	}

	CacheInfo(URL url, long fileSize, Bitmap value)
	{
		this.url = url;
		this.creatAt = System.currentTimeMillis();
		this.usetimes = 1;
		this.fileName = createFileName(url);
		this.fileSize = fileSize;
		this.value = value;
	}

	public static String createFileName(URL url)
	{
		if (url == null)
		{
			return "";
		}
		//		String urlPath = url.getPath();
		//		urlPath = urlPath.replaceAll("/", "_");
		//		return urlPath;
		try
		{
			return URLEncoder.encode(url.toString().replace("*", ""), "UTF-8");
		} catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public final long getCreatAt()
	{
		return this.creatAt;
	}

	public URL getUrl()
	{
		return this.url;
	}

	public void setUrl(URL url)
	{
		this.url = url;
	}

	public String getFileName()
	{
		return this.fileName;
	}

	public void setFileName(String fileName)
	{
		this.fileName = fileName;
	}

	public void setCreatAt(long creatAt)
	{
		this.creatAt = creatAt;
	}

	public long getFileSize()
	{
		return this.fileSize;
	}

	public void setFileSize(long fileSize)
	{
		this.fileSize = fileSize;
	}

	public Bitmap getValue()
	{
		return this.value;
	}

	public void setValue(Bitmap value)
	{
		this.value = value;
	}

	public int getUsetimes()
	{
		return this.usetimes;
	}

	public void setUsetimes(int usetimes)
	{
		this.usetimes = usetimes;
	}
}